"""author: wenyao
   data: 2021/5/6
   project: devopscmdb
"""
class Animal():
    species = "Animal"
    count = 0
    def __init__(self):
        self.name = "animal"
        Animal.count += 1
        print("初始化animal....")

    def breath(self):
        print("i can breath")

    def eat(self):
        print("i can eat")

class Person(Animal):
    species = "Person"  #重写父类的属性

class Dog(Animal):
    def __init__(self):  #重写父类的__init__
        print("i am dog")
    def eat(self):       #重写父类的eat方法
        print("dog is eating.....")

class Pig(Animal):
    count = 0
    def __init__(self):     #重写了父类的__init__
        super().__init__()  #子类访问父类的方法属性
        self.name = "pig"
        Pig.count += 1
        print("初始化pig...")

animal = Animal()
print(Animal.count, animal.count)
print("实例化person".center(30,"*"))
person = Person()
#继承父类的属性和方法
#对象属性查找，先在对象空间找，没有就去类空间，
# 类空间没有就去父类空间，层层递归往上查找
print(person.species, person.count, Person.count)
print("实例化dog".center(30,"*"))
dog1 = Dog()
print(dog1.count)
dog1.eat()
print("实例化pig".center(30,"*"))
pig = Pig()
print(pig.count, pig.name)

############类与实力的关系#########
print("类与实例的关系".center(30, "*"))
print(isinstance(dog1, Dog), isinstance(dog1, Animal))
print(type(dog1))
